import pygame

class Rocket:
    def __init__(self,r_game):
        self.screen = r_game.screen
        self.settings = r_game.settings

        self.screen_rect = r_game.screen.get_rect()

        self.image = pygame.image.load('day22/images/rocket_small.png')
        self.rect = self.image.get_rect()

        self.rect.center = self.screen_rect.center

        self.x = float(self.rect.x)
        self.y = float(self.rect.y)

        self.moving_right,self.moving_left = False,False
        self.moving_up,self.moving_down = False,False


    def update(self):
        """根据移动标志调整飞船的位置"""
        # 更新飞船的属性x的值，而不是外接矩形的属性x的值
                                #self.rect.right返回飞船外接矩形右边缘x的坐标
        if self.moving_right and self.rect.right<self.screen_rect.right:
            self.x += self.settings.rocket_speed

        if self.moving_left and self.rect.left>0:
            self.x -= self.settings.rocket_speed

        if self.moving_up and self.rect.top>0:
            self.y -= self.settings.rocket_speed
        if self.moving_down and self.rect.bottom<self.screen_rect.bottom:
            self.y += self.settings.rocket_speed

        # 根据 relf.x 更新 rect 对象
        self.rect.x = self.x 
        self.rect.y = self.y
    # 将图像绘制到self.rect指定位置
    def blitme(self):
        """在指定位置绘制飞船"""
        self.screen.blit(self.image,self.rect)